package com.event.core.listener;

import cn.hutool.core.util.ObjectUtil;
import com.event.common.model.ClassAnnotationEvent;
import com.event.common.model.MethodAnnotationEvent;
import com.event.common.face.IAnnotationHandle;
import com.google.common.eventbus.Subscribe;

/*
 * @description 注解监听器
 * @author Bing
 * @date 2024/10/8 14:07
 **/
public class AnnotationListener {
    /**
     * 注解处理句柄
     */
    private IAnnotationHandle annotationHandle;

    public AnnotationListener(IAnnotationHandle annotationHandle) {
        this.annotationHandle = annotationHandle;
    }

    @Subscribe
    public void methodEvent(MethodAnnotationEvent methodAnnotationEvent){
        if(ObjectUtil.isNull(annotationHandle)){
            return;
        }
        annotationHandle.handle(methodAnnotationEvent);
    }

    @Subscribe
    public void classEvent(ClassAnnotationEvent classAnnotationEvent){
        if(ObjectUtil.isNull(annotationHandle)){
            return;
        }
        annotationHandle.handle(classAnnotationEvent);
    }
}
